//封装一个存储到本地的方法

//存需要转成JSON
let set = (key, value) => {
    if (key && value) {
        //把value转成JSON
        try {
            let json = JSON.stringify(value)
            localStorage.setItem(key, json)
        } catch (e) {
            console.error(e)
        }
    } else {
        console.error('key和value必须传递')
    }
}

//取需转成正常的对象
let get = (key) => {
    let res = localStorage.getItem(key)
    try {
        let result = JSON.parse(res)
        return result
    } catch (e) {
        console.log(e);
        return null
    }
}
export default {
    set,
    get
}